<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" class="word" />
    <ul class="container"></ul>
    <script>
      let container = document.querySelector(".container");
      function jsonp_0(res) {
        console.log(res);
        container.innerHTML = "";
        res.s.forEach((item) => {
          let liEle = document.createElement("li");
          liEle.innerHTML = item;
          container.appendChild(liEle);
        });
      }
      // https://suggestion.baidu.com/su?wd=111&cb=jsonp_0
      let inp = document.querySelector(".word");
      inp.oninput = function () {
        let val = this.value;
        //   console.log(val);
        if (val == "") {
          container.innerHTML = "";
        } else {
          let s = document.createElement("script");
          s.src = `https://suggestion.baidu.com/su?wd=${val}&cb=jsonp_0`;
          document.head.appendChild(s);
        }
      };
    </script>
  </body>
</html>
